<?php
/*
Copyright FLV Hosting 
*/

	require_once '../config.php' ;

	// if(!isset($_SERVER['PHP_AUTH_USER']) || ($_SERVER['PHP_AUTH_USER']!=_ADMIN_LOGIN || $_SERVER['PHP_AUTH_PW'] != _ADMIN_PASSWORD)) {
	//   header('WWW-Authenticate: Basic realm="Administration"');
	//   header('HTTP/1.0 401 Unauthorized');
	//   echo '<p><center><b>This site requires a valid login and password.</b></center>';
	//   exit;
	// }

	 $is_logged = Session::isLogin();
	 if  (!$is_logged) {
		header('Location: '. 'http://'._HOST.'/login.htm');
		return;
	 }

     $user_id = Session::getUserId();
     $is_admin = User::isUserAdmin($user_id);
     $is_author = User::isUserArticleWriter($user_id);
     if  (!$is_admin && !$is_author) {
		header('Location: '. 'http://'._HOST.'/myprofile/index.htm');
		return;
	 }
 

	require_once _LIB.'/abstract.php' ;
	require_once _LIB.'/mysql.php' ;
	require_once _LIB.'/paginate.php' ;
	require_once _LIB.'/main.php' ;


	function save_file($fl, $fld = 'movies') {
		
		if(file_exists(_APP . '/'. $fld . '/'. $fl['u_file']['name'])) {
			@unlink($fl['u_file']['tmp_name']);
			return sprintf('File "%s" already exists',$fl['u_file']['name']) ;
		}
		if($fl['u_file']['error']) { 
				@unlink($fl['u_file']['tmp_name']);
				return sprintf('Upload error: %s', $fl['u_file']['error']) ; 
		}
		if(!ereg('\.flv$',$fl['u_file']['name'])) {
			@unlink($fl['u_file']['tmp_name']);
				return sprintf('Upload error: the file you are trying to upload must have a .flv extension!') ; 
		} // i f
		if (is_uploaded_file($fl['u_file']['tmp_name'])){
			$wrn = @move_uploaded_file($fl['u_file']['tmp_name'], _APP . '/'. $fld . '/'. $fl['u_file']['name']);
			if(!$wrn) {
				return 'File upload cannot be completed' ;
			}
			else {
				@chmod(_APP . '/'. $fld . '/'. $fl['u_file']['name'], 0777);
			} // e l s e
		}
		return 'File uploaded' ;
	}	
	
	# workout 
	if(isset($_FILES[u_file])) {
		$MSG = save_file($_FILES);
	}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Manage movies</TITLE>
<link rel="stylesheet" type="text/css" href="admin.css">
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="10" topmargin="20" marginwidth="0" marginheight="0">

<TABLE border=0 cellspacing=0 cellpadding=10 align=center width=620>
<tr>
	<td width=160 style="border-right: 4px double red;" valign=top>
		<b>Help section:</b>
		<ul>
			<li style="font-size: xx-small;">Warning: you will waste your time if you'd try to upload files more than 2Mb, most of servers will not accept files of more than this size. Use ftp for such purposes.
			<li style="font-size: xx-small;">Select a local file (.flv extension only) in the form on the right and click "upload". This will bring the file directly to the "movies" folder.
			<li style="font-size: xx-small;"><a href="index.php" style="font-size: xx-small;">Return to file list</a>.
		</ul>
	</td>
	<td valign=top>
		<h1>Upload FLV files</h1>

<?php
	if(!empty($MSG)) {
		echo '<h2>'.$MSG.'</h2>'._E ;
	} // i f 
?>

<table align="center" width=100% border=1 cellspacing=2 cellpadding=2>
<form method=post enctype="multipart/form-data">
<tr>
	<td width=50%>
		<input type="file" name="u_file" value="" class="usual" style="width: 100%;"> 
	</td>
	<td align=center>
		<input type="submit" name="upl" value="upload">	
	</td>
</tr>
</form>
</table>
<?php
# right area


# right area end
?>
	</td>
</tr>
<tr>
	<td colspan=2 align=center>
<BR>
<BR>
<BR>
<BR>
<a href="http://affiliates.macromedia.com/b.asp?id=2097&p=go/dr_home_aff1" target="_blank"><IMG SRC="../system/mwm_flmx_88_31.gif" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Powered By Flash MX"></A>&nbsp;&nbsp;<A HREF="http://www.php.net" target="_blank"><IMG SRC="../system/powered_by_php.jpg" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Powered By PHP"></A>&nbsp;&nbsp;<A HREF="http://www.macromedia.com/go/getflashplayer/" target="_blank"><IMG SRC="../system/alternate.gif" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Get the latest Free Flash Player"></A>	
	</td>
</tr>
</table>

</BODY>
</HTML>